<?php
/*
*	created by cbq in 2017.02.08
*	系统日志模型类
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class AdminuserLoginLog_m extends MY_Model {
    public function __construct()
    {
        parent::__construct();
        $this->table='adminuser_loginlog';
    }
    //写入登陆信息到数据库
    public function addloginlog($arr=array(),$type=true){
      if(empty($arr)){
        return false;
      }
      $data=array();
      $data['username']=$arr['username'];
      if($type){
        $data['resultflag']=1;
        $data['description']='登陆成功';
      }else{
        $data['resultflag']=2;
        $data['description']='登陆失败';
      }
      if(isset($arr['description'])){
        $data['description']=$arr['description'];
      }
      $data['loginip']=get_client_ip();
      $data['logintime']=time();
      $data['loginurl']=$arr['url'];
      $this->db->insert($this->table,$data);
      return $this->db->affected_rows();
    }
    //是否锁定
    public function is_lock(){
      $count=0;
      $logintimes=getConfig('admin_locked')+1;//登陆次数限定
      $where['loginip']=array('=',get_client_ip());
      $this->com_where($where);
      $this->db->order_by('id','desc');
      $this->db->select('loginip,resultflag');
      $query=$this->db->get($this->table);
      $result=$query->row_array();
      if($result['resultflag']==2){
          $count=++$count;
      }
      if($count==$logintimes){
        //修改数据库锁定状态
        return false;
      }else{
        return true;
      }
    }
    
  
}
?>
